package dymnd.ui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;

import dymnd.plugin.PaintPlugin;

public class PluginOptionPanel extends JPanel implements ActionListener{

	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 234235435;
	Image loadedImage = loadImage("resources/menupane2.png");
	public PluginOptionPanel(){
		setBackground(ThemeConstants.THEME_PLUGIN_PANEL_COLOR);
		setLayout(null);
	}
	
	public void actionPerformed(ActionEvent e)	{
		if(e.getSource() instanceof PaintPlugin)	{
			onPluginSelected((PaintPlugin)e.getSource());
		}
	}
	
	
	public void onPluginSelected(PaintPlugin p)	{
		removeAll();
		add(p.getToolbar(getSize()));
	}
	
	public void paintComponent(Graphics g)  {
        g.setColor(getBackground());
        g.fillRect(0, 0, getWidth(), getHeight());
        if(loadedImage != null)
            for(int x = 0; x*loadedImage.getWidth(this) <= getWidth()+ 100; x++) {
                g.drawImage(loadedImage, x*loadedImage.getWidth(this), 0, this);
            }
        else    {
            g.setColor(new Color(255, 255, 255, 50));
            g.fillRect(0, 0, getWidth(), getHeight()/2);
            
            g.setColor(new Color(0, 0, 50, 50));
            g.fillRect(0, getHeight()/2+1, getWidth(), getHeight()/2);
        }
        //paintChildren(g);
       /* if(getComponentCount() > 0)
        	getComponent(0).repaint();*/
    }
	
/*	public void paint(Graphics g)	{
		paintComponent(g);
		paintChildren(g);
	}
*/	
	private Image loadImage(String name)   {
       return Toolkit.getDefaultToolkit().getImage(name);
		/* try {
            return ImageIO.read(ClassLoader.getSystemResourceAsStream(name));
        }   catch(Exception x)  {
            x.printStackTrace();
        }
        System.out.println("crap! ><");
        return null;*/
    }
	
	
}
